<template>
    <div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-table layui-form">
                                <thead>
                                <tr>
                                    <th>姓名</th>
                                    <th>手机</th>
                                    <th>模糊信息</th>
                                    <th>模糊需求</th>
                                    <th>创建人</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr v-for="item in leadData">
                                    <td>
                                        {{item.name}}
                                    </td>
                                    <td>
                                        {{item.phone}}
                                    </td>
                                    <td>
                                        {{item.company}}
                                    </td>
                                    <td>
                                        {{item.leadsDetail}}
                                    </td>
                                    <td>
                                        {{item.creater}}
                                    </td>
                                    <td class="td-manage" style="width: 17%">
                                        <a title="恢复" class="layui-btn" @click.stop="recovery(item.id,item.name)" href="javascript:;">
                                            <i class="layui-icon">恢复</i>
                                        </a>&nbsp
                                        <a title="彻底删除" class="layui-btn layui-btn-danger" @click="del(item.id,item.name)" href="javascript:;">
                                            <i class="layui-icon">彻底删除</i>
                                        </a>
                                    </td>

                                </tr>
                                </tbody>
                            </table>
                            <my-page :total="count"></my-page>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>

    import { mapActions, mapState } from "vuex";
    import leadedit from './lead-edit';
    import page from './pagination6'
    import leadadd from './lead-add'

    export default {
        data(){
            return{
            }
        },
        name: "leaddrop",
        components:{
            'my-page':page
        },
        created() {
            this.getdropleads();
            this.getleadsDropCounts();
        },
        computed:{
            ...mapState({
                leadData:state=>state.leadDropData,
                count:state=>state.leadDropCount,
            })
        },
        methods:{
            del(id,name){
                let vm = this
                layer.confirm('确认彻底删除 '+name+' ？',function(){
                    vm.deletelead(id);
                    setTimeout(vm.getdropleads,500);
                    setTimeout(vm.getleadsDropCounts,500);
                });
            },
            recovery(id,name){
                let vm = this;
                layer.confirm('恢复 '+name+' 至正常线索池？',function(){
                    vm.recoverylead(id);
                    setTimeout(vm.getdropleads,500);
                    setTimeout(vm.getleadsDropCounts,500);
                });
                this.$layer.alert("已恢复"+name+"到正常线索池");
            },


            ...mapActions(["getdropleads","getleadsDropCounts","deletelead","recoverylead"])
        },
        mounted(){
            layui.use(['laydate','form'], function(){
                var laydate = layui.laydate;
                var  form = layui.form;


                // 监听全选
                form.on('checkbox(checkall)', function(data){

                    if(data.elem.checked){
                        $('tbody input').prop('checked',true);
                    }else{
                        $('tbody input').prop('checked',false);
                    }
                    form.render('checkbox');
                });

                //执行一个laydate实例
                laydate.render({
                    elem: '#start' //指定元素
                });

                //执行一个laydate实例
                laydate.render({
                    elem: '#end' //指定元素
                });


            });


            function delAll (argument) {
                var ids = [];

                // 获取选中的id
                $('tbody input').each(function(index, el) {
                    if($(this).prop('checked')){
                        ids.push($(this).val())
                    }
                });

                layer.confirm('确认要删除吗？'+ids.toString(),function(index){
                    //捉到所有被选中的，发异步进行删除
                    layer.msg('删除成功', {icon: 1});
                    $(".layui-form-checked").not('.header').parents('tr').remove();
                });
            }
        },
    }


</script>

<style scoped>

</style>